/*
 * @Author: CemCode
 * @Date: 2023-10-07 10:16:54
 * @LastEditTime: 2023-10-07 11:01:55
 * @Description: file content
 */
const path = require("path")
const CompressionPlugin = require('compression-webpack-plugin')
const productionGzipExtensions = /\.(js|css|json|txt|html|ico|svg)(\?.*)?$/i
const resolve = (dir) => path.resolve(__dirname, dir)

module.exports = {
  publicPath: "/",
  lintOnSave: process.env.NODE_ENV !== 'production',
  devServer:{
    historyApiFallback:{
      index:"/index.html"
    }
  },
  configureWebpack: {
    externals: {
      echarts: "echarts",
      highlight: "highlight"
    }
  },
  chainWebpack: config => {
    config.resolve.alias.set('@', resolve('src'));
    if (process.env.NODE_ENV === 'production'){
      config.plugin('compressionPlugin')
        .use(new CompressionPlugin({
          filename: '[path].gz[query]',
          algorithm: 'gzip',
          test: productionGzipExtensions,
          threshold: 10240,
          minRatio: 0.8,
          deleteOriginalAssets: true
        }));
    }
  }
}